<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="./code/file_server.js"></script>
</head>

<body>
    <script>
        const { statSync, readdirSync, readFileSync } = require("fs");

        let searchTerm = new RegExp(process.argv[2]);

        for (let arg of process.argv.slice(3)) {
            search(arg);
        }

        function search(file) {
            let stats = statSync(file);
            if (stats.isDirectory()) {
                for (let f of readdirSync(file)) {
                    search(file + "/" + f);
                }
            } else if (searchTerm.test(readFileSync(file, "utf8"))) {
                console.log(file);
            }
        }

    </script>
</body>

</html>